import { any } from "../../core/logic";
import { Register } from "../../register/Register";
import { Component, ComponentType } from "../Component";
import { Evented, Event, EventType } from "../../event/index";
/**
 * 光照的基类。
 * @class
 * @extends w.component.Component
 * @memberof w.light
 */
class Light extends Component{
    /**
     * @constructor
     * @param {String} opts.color 【可选,缺省值:"#ffffff"】光照颜色
     * @param {Number} opts.intensity 光照强度。 
     */
    constructor(opts={}){
        super(opts);
        this._color =any(opts.color,"#ffffff");
        this._intensity =any(opts.intensity,1.0);
    }
    attach(eid){
        //绑定trans
        this._trans=Register.instance.entityManager.get(eid).getComponent(ComponentType.Trans);
        let self=this
        let i=0
        this._trans.onChange(()=>{
            if(this.cast&&i){
               this.inputShadowData()
                let ev = new Event(EventType.ShadowUpdate)
                this.publish(ev);//抛出舞台改变事件
            }
            self.update()
            i++
        });
        super.attach(eid);
    }
    update(){
        this.setState(false,"lightBuffer");
        super.update();
    }
   /**
   * @property {w.component.Trans} 平行光的trans属性。
   * @readonly
   */
    get trans(){
        return this._trans;
    }
   /**
   * @property {String} 光照的颜色属性。
   */
    set color(v){
        this._color=v;
        this.setState(false,"lightBuffer");
        this.update();
        return this;
    }
    get color(){
        return this._color;
    }
   /**
   * @property {Number} 光照的强度。
   */
    set intensity(v){
        this._intensity=v;
        this.setState(false,"lightBuffer");
        this.update();
        return this;
    }
    get intensity(){
        return this._intensity;
    }
}
export {Light}